from models import User
from functools import wraps
from src.common.code import Code,make_result

def check_token(token):
    id = User.check_auth_token(token)
    if id:
        return id
    else:
        return None

def check(token):
    def check_token_1(func):
        @wraps(func)
        def check(*args,**kwargs):
            if not token or check_token(token) is None:
                return make_result(code=Code.VALID_TOKEN)
            else:
                return func(*args,**kwargs)
        return check
    return check_token_1
